package com.itheima.myscoket.test6;

import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;

public class ServerDemo {
    public static void main(String[] args) throws IOException {
        //创建接受流用于接收服务器发过来的数据
        ServerSocket ss = new ServerSocket(10000);
        //生成socket,等待连接
        Socket accept = ss.accept();
        //读写数据,创建得到
        InputStream is = accept.getInputStream();
        int b;
        while ((b = is.read()) != -1) {
            System.out.println((char) b);

        }
        //当服务器接收到船坞的数据再反馈给链接,此时是写入是数据
//        OutputStream os = accept.getOutputStream();
//        os.write("你好!".getBytes());
//        accept.close();
//        ss.close();
//        is.close();
        BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(accept.getOutputStream()));
        bw.write("你好!");
        bw.newLine();
        bw.flush();
        accept.close();
        bw.close();
        ss.close();
        is.close();
    }
}
